package com.YxyBackMange.Controller.App;


import com.YxyBackMange.Dto.Message;
import com.YxyBackMange.Entity.App.AppFeedback;
import com.YxyBackMange.Mapper.App.AppFeedbackMapper;
import com.YxyBackMange.Service.App.AppFeedbackService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@RequestMapping("/Admin/App/AppFeedback")
public class  AppFeedbackController {

    private Logger logger= LoggerFactory.getLogger(AppFeedbackController.class);

    @Autowired
    private AppFeedbackService appFeedbackService;

    @Autowired
    private  AppFeedbackMapper appFeedbackMapper;

    @RequestMapping("/listPage")
    public String listPage(HttpSession session, ModelMap map){

        return "/admin/page/App/AppFeedback/listAppFeedbackPage.jsp";

    }
    @RequestMapping("/addPage")
    public String addPage(HttpSession session, ModelMap map){

        return "/admin/page/App/AppFeedback/updateAppFeedbackPage.jsp";
    }
    @RequestMapping("/detailPage")
    public String detailPage(HttpSession session, @RequestParam Integer id, ModelMap map){
        AppFeedback appFeedback=new AppFeedback(id);
        appFeedback=appFeedbackMapper.selectByPrimaryKey(appFeedback);
        map.put("obj",appFeedback);
        return "/admin/page/App/AppFeedback/detailAppFeedbackPage.jsp";

    }
    @RequestMapping("/updatePage")
    public String updatePage(HttpSession session, @RequestParam Integer id, ModelMap map){

        AppFeedback appFeedback=new AppFeedback(id);
        appFeedback=appFeedbackMapper.selectByPrimaryKey(appFeedback);
        map.put("obj",appFeedback);
        return "/admin/page/App/AppFeedback/updateAppFeedbackPage.jsp";
    }
    @RequestMapping("/addOrUpdate")
    @ResponseBody
    public Message addOrUpdate(AppFeedback appFeedback,HttpSession session )
    {
        Message msg=new Message();
        try{
            if(appFeedback!=null&&appFeedback.getId()!=null)
            {
                 appFeedback=appFeedbackService.updateService(appFeedback);
            }else{

                  appFeedback=appFeedbackService.insertService(appFeedback);
            }
            if(appFeedback==null)
            {
                msg.setMsg("操作失败,您可以稍后重试!");
                return msg;
            }
            msg.setData(appFeedbackMapper.selectQueryById(appFeedback.getId()));
            msg.setMsg("保存成功！");
            msg.setState(true);
            logger.info("保存成功:"+msg);
            return msg;
        }catch (Exception e)
        {
            msg.setMsg("保存失败，请稍后重试");
            e.printStackTrace();
            logger.error("保存失败:"+e.getMessage());
            return msg;
        }
    }
    @RequestMapping("/update")
    @ResponseBody
    public Message update(AppFeedback appFeedback,HttpSession session)
    {
        Message msg=new Message();
        try{
            appFeedbackService.update(appFeedback);
            msg.setData(appFeedbackMapper.selectByPrimaryKey(appFeedback));
            msg.setMsg("更新成功！");
            msg.setState(true);
             logger.info("更新成功:"+msg);
            return msg;
        }catch (Exception e)
        {
            msg.setMsg("更新失败，请稍后重试");
            e.printStackTrace();
            logger.error("更新失败:"+e.getMessage());
            return msg;
        }
    }
    @RequestMapping("/delete")
    @ResponseBody
    public Message delete(@RequestParam Integer id, HttpSession session)
    {
        Message msg=new Message();
        try{
            AppFeedback appFeedback=new AppFeedback(id);
            appFeedbackService.delete(appFeedback);
            msg.setData(appFeedback);
            msg.setMsg("删除成功！");
            msg.setState(true);
            logger.error("删除成功:"+msg);
            return msg;
        }catch (Exception e)
        {
            msg.setMsg("删除失败，请稍后重试");
            logger.error("更新失败:"+e.getMessage());
            e.printStackTrace();
            return msg;
        }
    }
}
